﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/WithoutPermBasic.Master" AutoEventWireup="true" CodeBehind="ContractDetail.aspx.cs" Inherits="PMS.UI.CM.ContractDetail" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script type="text/javascript">
        $(function () {
            var rowData;
            var height = $("#divTotal").height();
            var content = parseFloat(height) - 30;
            $("#tbList").css("height", content);
            loadTopForm();
        });
    </script>

    <script type="text/javascript">
        //加载头部表单
        function loadTopForm() {
            //不同报价单，主表信息一致，所以可以随意选取一个ID
            var paramID = com.get.ID;
            var action = com.get.action;
            // 查看，由主表跳转
            if (action == "view") {
                $.ajax({
                    type: "POST", dataType: "json",
                    url: "/Logic/CM/ContractAjax.aspx?method=GetContractByID&id=" + paramID,
                    success: function (data) {
                        $("#form1").form("load", data);
                    }
                })
            }
            else if (action == "add") {
                $.ajax({
                    type: "POST", dataType: "json",
                    url: "/Logic/CM/ContractAjax.aspx?method=GetContractByID&quotID=" + paramID,
                    success: function (data) {
                        $("#form1").form("load", data);
                    }
                })
            }
        }

        function getMultiParam() {
            //?action=add&ID=1&ID=2&ID=3&ID=4&ID=5
            var url = window.document.location.href.toString();
            var u = url.split("?");
            u = u[1].split("&");
            var get = {};
            if (typeof (u[1]) == "string") {
                for (var i in u) {
                    var j = u[i].split("=");
                    if (get.hasOwnProperty(j[0])) {
                        if (Array.isArray(get[j[0]])) {
                            get[j[0]].push(j[1])
                        } else {
                            get[j[0]] = [get[j[0]], j[1]];
                        }
                    }
                    else {
                        get[j[0]] = j[1];
                    }
                }
            }
            return get;
        }
    </script>

    <script type="text/javascript">
        // 加载产品细则
        $(function () {
            var contID = undefined;
            var quotationID = undefined;
            var action = com.get.action;
            if (action == "add") {
                var params = getMultiParam();
                quotationID = params.ID;
            }
            if (action == "view") {
                contID = com.get.ID;
            }
            $("#tbList").datagrid({
                url: '/Logic/CM/QuotationAjax.aspx?method=GetAllProductDetailByID',
                queryParams: { "quotID": JSON.stringify(quotationID), "contID": contID },
                loadMsg: '数据加载中请稍后……',
                rownumbers: true,
                striped: true,
                singleSelect: true,
                columns: [[
                    { field: 'QuotationCode', title: '报价单号', align: "center", width: 100 },
                    { field: 'QuotationDate', title: '报价日期', align: "center", width: 100 },
                    //{ field: 'QuotationDetailID', title: '细则ID', align: "center", width: 60 },
                    { field: 'ProductName', title: '产品名称', sortable: true, align: "center", width: 200 },
                    {
                        field: 'TechParams', title: '技术参数', align: "center", width: 200,
                        formatter: function (value, row, index) {
                            if (value == null) return "还未生成技术参数信息...";
                            //鼠标放在文本处自动显示tooltip
                            return '<span title=' + value + '>' + value + '</span>';
                        }
                    },
                    { field: 'BottleVolume', title: '规格（L）', align: "center", width: 60 },
                    { field: 'OrderCount', title: '计划数量', align: "center", width: 60 },
                     { field: 'unit', title: '单位', align: "center", width: 60 },
                    { field: 'SinglePrice', title: '单价', align: "center", width: 60 },
                    { field: 'TotalPrice', title: '总价', align: "center", width: 60 },
                    { field: 'Note', title: '备注', align: "center", width: 60 }]],
                onLoadSuccess: function (data) {
                    com.mergeCells("tbList", "QuotationCode,QuotationDate");
                }
            });

        })
    </script>

    <script type="text/javascript">

        //保存
        function funcSave() {
            var params = getMultiParam();
            var quotID = params.ID;
            var contractInfo = com.serializeObj("form1");
            var extend = {FillPerson: $("#FillPerson").textbox('getValue') }
            $.extend(contractInfo, extend);
            contractInfo.quotID = JSON.stringify(quotID);
            com.ajax({
                url: '/Logic/CM/ContractAjax.aspx?method=AddContract',
                data: contractInfo,
                success: function (data) {
                    com.message(data.state, data.msg);
                    if (data.state == "success") {
                        top.wrapper.tabClosethisRefreshByTitle("报价单信息");
                    }

                }
            });
        }
        //重置
        function funcReload() {
            loadTopForm();
        }
    </script>
</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceToorbar" runat="server">
   <a href="javascript:void(0)" id="btnSave" class="easyui-linkbutton" onclick="funcSave()"
        data-options="iconCls:'icon-save',plain:true">保存</a> &nbsp;&nbsp;
    <a href="javascript:void(0)" id="btnReset" class="easyui-linkbutton" onclick="funcReload()"
        data-options="iconCls:'icon-reload',plain:true">重置</a> &nbsp;&nbsp;
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <div id="divTotal" style="height: auto; width: 100%">
        <div id="master" class="container_16" style="height: auto">
            <form id="form1">
                <div id="title" class="grid_16" style="text-align: center">
                    <h1>产品销售合同</h1>
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    合同编号 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="Code" name="Code" disabled="disabled" />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    合同名称 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="ContractName" name="ContractName" class="easyui-textbox" />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    签订地点 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="Address" name="Address" />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    签订时间 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="SignDate" name="SignDate" class="easyui-datebox" />
                </div>
                <div class="Clear"></div>
                <div class="grid_2 lbl" style="text-align: right;">
                    供方 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="SupplierName" name="SupplierName" class="easyui-textbox" disabled="disabled" />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    需方 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="CustomerName" name="CustomerName" class="easyui-textbox" disabled="disabled" />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    制单人 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="FillPerson" name="FillPerson" class="easyui-textbox" disabled="disabled" />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    备注 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="Note" name="Note" class="easyui-textbox" />
                </div>
            </form>
        </div>
    </div>
    <div id="productDetail" style="height: auto; width: 100%">
        <table id="tbList" title="产品信息" style="width: 100%">
        </table>
    </div>

    <script type="text/javascript">
        $(function(){
            var action = com.get.action;
            if (action == "view") {
                $("#ContractName").attr("disabled", "disabled");
                $("#Address").attr("disabled", "disabled");
                $("#SignDate").attr("disabled", "disabled");
                $("#Note").attr("disabled", "disabled");
                $("#btnSave").linkbutton('disable');
                $("#btnReset").linkbutton('disable');
                //$("#btnSave").attr("data-options", "iconCls:'icon-save',plain:true,disabled:true");
                //$("#btnReset").attr("data-options", "iconCls:'icon-reload',plain:true,disabled:true");
            }
        })
        
    </script>
</asp:Content>


